/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.employee.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.employee.dao.StoreBonusSettingTemplateCareDao;
import com.chlitina.store.modules.employee.entity.StoreBonusSettingTemplateCare;
import com.chlitina.store.modules.employee.entity.StoreBonusSettingTemplateProduct;
import com.chlitina.store.modules.sys.utils.StoreUtils;

/**
 * 手工护理提成设定模板Service
 * @author liujiang
 * @version 2013-11-15
 */
@Component
@Transactional(readOnly = true)
public class StoreBonusSettingTemplateCareService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(StoreBonusSettingTemplateCareService.class);
	
	@Autowired
	private StoreBonusSettingTemplateCareDao storeBonusSettingTemplateCareDao;
	
	public StoreBonusSettingTemplateCare get(Long id) {
		return storeBonusSettingTemplateCareDao.findOne(id);
	}
	
	public List<Long> getByCardType(int type) {
		return storeBonusSettingTemplateCareDao.getByCardType(StoreUtils.getStore().getId(), type);
	}
	
	public Page<StoreBonusSettingTemplateCare> find(Page<StoreBonusSettingTemplateCare> page, int type) {
		DetachedCriteria dc = storeBonusSettingTemplateCareDao.createDetachedCriteria();
		dc.add(Restrictions.eq("store", StoreUtils.getStore()));
		dc.add(Restrictions.eq("card_type", type));
		dc.addOrder(Order.desc("id"));
		return storeBonusSettingTemplateCareDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(StoreBonusSettingTemplateCare storeBonusSettingTemplateCare) {
		storeBonusSettingTemplateCareDao.save(storeBonusSettingTemplateCare);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		storeBonusSettingTemplateCareDao.delete(id);
	}
	
	public List<StoreBonusSettingTemplateCare> getByStore() {
		DetachedCriteria dc = storeBonusSettingTemplateCareDao.createDetachedCriteria();
		dc.add(Restrictions.eq("store", StoreUtils.getStore()));
		dc.addOrder(Order.desc("id"));
		return storeBonusSettingTemplateCareDao.find(dc);
	}
}
